﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="NegativeOrZeroSizeException.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Exceptions
{
    #region Usings

    using System;
    using System.Globalization;
    using System.Runtime.Serialization;
    using System.Security;

    using ExulLibrary.Properties;

    #endregion

    /// <summary>
    ///     Describes an error when size parameter is negative or equal to zero.
    /// </summary>
    [Serializable]
    public sealed class NegativeOrZeroSizeException : ArgumentException
    {
        #region Constructors and Destructors

        #region public

        /// <summary>
        ///     Initializes a new instance of the <see cref="NegativeOrZeroSizeException"/> class.
        /// </summary>
        /// <param name="paramName">
        ///     The parameter name.
        /// </param>
        /// <param name="actualValue">
        ///     The actual value of parameter.
        /// </param>
        public NegativeOrZeroSizeException(string paramName, int actualValue)
            : this(paramName, actualValue, null)
        {
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="NegativeOrZeroSizeException"/> class.
        /// </summary>
        /// <param name="paramName">
        ///     The parameter name.
        /// </param>
        /// <param name="actualValue">
        ///     The actual value of parameter.
        /// </param>
        /// <param name="innerException">
        ///     The inner exception.
        /// </param>
        public NegativeOrZeroSizeException(string paramName, int actualValue, Exception innerException)
            : base(Resources.SizeIsNegativeOrZero, paramName, innerException)
        {
            this.ActualValue = actualValue;
        }

        #endregion

        #region private

        /// <summary>
        ///     Initializes a new instance of the <see cref="NegativeOrZeroSizeException"/> class.
        /// </summary>
        /// <param name="info">
        ///     The object that holds the serialized object data.
        /// </param>
        /// <param name="context">
        ///     An object that describes the source or destination of the serialized data.
        /// </param>
        private NegativeOrZeroSizeException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            this.ActualValue = info.GetInt32("ActualValue");
        }

        #endregion

        #endregion

        #region Properties

        #region public

        /// <summary>
        ///     Gets the actual value of parameter.
        /// </summary>
        /// <value>
        ///     The actual value of parameter.
        /// </value>
        public int ActualValue
        {
            get;
            private set;
        }

        #endregion

        #endregion

        #region Overridden Properties

        #region public

        /// <summary>
        ///     Gets the error message and the string representation of the invalid argument value,
        ///     or only the error message if the argument value is null.
        /// </summary>
        /// <value>
        ///     The text message for this exception.
        /// </value>
        public override string Message
        {
            get
            {
                return string.Format(CultureInfo.CurrentCulture, base.Message, this.ParamName, this.ActualValue);
            }
        }

        #endregion

        #endregion

        #region Overridden Methods

        #region public

        /// <summary>
        ///     Sets the <see cref="SerializationInfo"/> object with the parameter name and additional exception information.
        /// </summary>
        /// <param name="info">
        ///     The object that holds the serialized object data.
        /// </param>
        /// <param name="context">
        ///     The contextual information about the source or destination.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="info"/> is <see langword="null"/>.
        /// </exception>
        [SecurityCritical]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            info.AddValue("ActualValue", this.ActualValue);
        }

        #endregion

        #endregion
    }
}